

package cup.modules.visual.log;

import cup.core.log.constant.EventConstant;
import cup.core.tool.utils.DateUtil;
import cup.core.tool.utils.SpringUtil;
import cup.core.tool.utils.UrlUtil;
import cup.core.tool.utils.WebUtil;
import cup.modules.visual.entity.VisualLog;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 大屏日志信息事件发送
 *
 *
 */
public class VisualLogPublisher {

	public static void publishEvent(String methodName, String methodClass, String title, long time) {
		HttpServletRequest request = WebUtil.getRequest();
		VisualLog log = new VisualLog();
		log.setTitle(title);
		log.setTime(String.valueOf(time));
		log.setMethodClass(methodClass);
		log.setMethodName(methodName);
		log.setRemoteIp(WebUtil.getIP(request));
		log.setUserAgent(request.getHeader(WebUtil.USER_AGENT_HEADER));
		log.setRequestUri(UrlUtil.getPath(request.getRequestURI()));
		log.setMethod(request.getMethod());
		log.setParams(WebUtil.getRequestContent(request));
		log.setCreateTime(DateUtil.now());
		Map<String, Object> event = new HashMap<>(16);
		event.put(EventConstant.EVENT_LOG, log);
		SpringUtil.publishEvent(new VisualLogEvent(event));
	}

}
